package com.custom.base.util

import android.app.Activity
import android.app.Dialog
import android.view.WindowManager

/**
 * 作者：
 * 时间：12/15/20
 * 描述：状态栏相关工具类
 */
object StatusBarUtils {
    //设置Activity对应的顶部状态栏的颜色
    fun setWindowStatusBarColor(activity: Activity, colorResId: Int) {
        try {
            val window = activity.window
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor = activity.resources.getColor(colorResId)
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

    //设置Dialog对应的顶部状态栏的颜色
    fun setWindowStatusBarColor(dialog: Dialog, colorResId: Int) {
        try {
            val window = dialog.window
            window!!.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor = dialog.context.resources.getColor(colorResId)
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }
}
